/**
 * Created by henian.xu on 2018/10/9.
 *
 */

import createInterceptors from './interceptors';
import HttpCommBase from './HttpCommBase';

export default {
    install(Vue, { apiBase, router, GlobalVar } = {}) {
        const { /*HttpBase, HttpInstance,*/ axiosInstance, axiosInstanceMock } = apiBase;
        // console.log(HttpBase, '\n\n', HttpInstance, '\n\n', axiosInstance, '\n\n', axiosInstanceMock, '\n\n');
        const { requestSuccess, requestFail, responseSuccess, responseFail } = createInterceptors({
            router,
            GlobalVar,
        });
        // 请求拦截
        axiosInstance.interceptors.request.use(requestSuccess, requestFail);
        // 响应拦截
        axiosInstance.interceptors.response.use(responseSuccess, responseFail);
        if (axiosInstanceMock) {
            axiosInstanceMock.interceptors.request.use(requestSuccess, requestFail);
            axiosInstanceMock.interceptors.response.use(responseSuccess, responseFail);
        }
    },
};

export { HttpCommBase };
